package com.cloneoner.ui.shapes
{
	import flash.display.Graphics;
	import flash.display.Shape;



	/**
	 * @author Thibault Loup
	 */
	public class ShPlus extends Shape
	{


		// __________________________________________________________
		// -										 	  CONSTRUCTOR
		
		/**
		 * Constructor
		 * @param pColor The color of the object
		 * @param pWidth The width of the object in pixels.
		 * @param pHeight The height of the object in pixels.
		 * @param pThickness The thickness of the object in pixels
		 */
		public function ShPlus(pColor : uint, pWidth : int, pHeight : int = -1, pThickness : int = -1)
		{
			_color = pColor;
			_width = pWidth;
			_height = (_width > 0 && pHeight == 0 ) ? _width : pHeight;
			_thickness = pThickness;

			_draw();
		}

		// __________________________________________________________
		// -										  PUBLICS METHODS
		
		/** The color of the object */
		public function set color(c : uint) : void
		{
			_color = c;
			_draw();
		}
		public function get color() : uint
		{
			return _color;
		}

		/** The width of the object in pixels. */
		override public function set width(value : Number) : void
		{
			_width = value;

			_draw();
		}
		override public function get width() : Number
		{
			return _width;
		}

		/** The height of the object in pixels. */
		override public function set height(value : Number) : void
		{
			_height = value;

			_draw();
		}
		override public function get height() : Number
		{
			return _height;
		}

		/** The thickness of the object in pixels. */
		public function set thickness(thickness : int) : void
		{
			_thickness = thickness;

			_draw();
		}
		public function get thickness() : int
		{
			return _thickness;
		}

		// __________________________________________________________
		// -										 PRIVATES METHODS
		/** @private */
		private function _draw() : void
		{
			var g : Graphics = this.graphics;

			var xx : int = int(_width / 2 + .5);
			var yy : int = int(_height / 2 + .5);
			var th : int = int(_thickness / 2 + .5);

			g.clear();
			g.beginFill(_color);
			g.moveTo(-xx, 0);
			g.lineTo(-xx, -th);
			g.lineTo(-th, -th);
			g.lineTo(-th, -yy);
			g.lineTo(th, -yy);
			g.lineTo(th, -th);
			g.lineTo(xx, -th);
			g.lineTo(xx, th);
			g.lineTo(th, th);
			g.lineTo(th, yy);
			g.lineTo(-th, yy);
			g.lineTo(-th, th);
			g.lineTo(-xx, th);
			g.lineTo(-xx, 0);
			g.endFill();
		}


		/* VAR */
		private var _color : uint = 0;
		private var _width : int;
		private var _height : int;
		private var _thickness : int;
	}
}
